//
//  WebViewController.swift
//  ADKit_Example
//
//  Created by 余林淋 on 2024/1/2.
//  Copyright © 2024 CocoaPods. All rights reserved.
//

import ADKit
import WebKit

class WebViewController: ADWebViewController {
    
    var handler: ScriptMessageHandler?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        showControlView = false
        
        titleSubject.subscribe(onNext: { title in
            self.title = title
        }).disposed(by: rx.disposeBag)
    }
    
    override func customConfiguration(userContent: WKUserContentController) {
        
        let phone = MessageHandler(name: "phone") { (body) in
            UIApplication.shared.open(URL.init(string: "tel://\(body.stringValue)")!)
        }
        
       let handler = ScriptMessageHandler(handlers: [phone])
        userContent.add(handler: handler)
        self.handler = handler
    }
    
    deinit {
        self.handler?.removeFromController()
    }
}
